<template>
  <div class="repList">
    <CommonBtn label-name="人员信息管理 <span style='color:red'>数据来源:TP系统自动同步</span>" v-if="!button || (button.event!='add()' && button.event!='edit()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+(item.type=='search'?item.proxy:item.value)}}</span>
    </CommonBtn>
    <CommonList ref="list" v-show="!button || (button.event!='add()' && button.event!='edit()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions"></CommonList>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_TPINFOEXPORT" :conditions="conditions"></CommonExport>

    <CommonEdit v-if="button && (button.event=='add()' || button.event=='edit()')"
                :outBtn="button" :props="add"
                :original-data="row" :edit-url="$api.API_GETTPINFO_UPDATE"
                @editBack="editBack"></CommonEdit>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList"
    import CommonBtn from "../../common/CommonBtn";
    import CommonEdit from "../../common/CommonEdit";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    export default {
        name:'repList',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.EDIT,
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'repCode',
                        label:'用户账号',
                        minWidth:'80',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'repName',
                        label:'真实姓名',
                        minWidth:'80',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'wWID',
                        label:'WWID',
                        minWidth:'80',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'companyCode',
                        label:'公司编码',
                        minWidth:'80'
                    },
                    {
                        prop:'deptCode',
                        label:'公司部门',
                        minWidth:'80'
                    },
                    {
                        prop:'email',
                        label:'邮件地址',
                        minWidth:'80'
                    },
                    {
                        prop:'positionName',
                        label:'所属管理层级',
                        minWidth:'120',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop: 'positionName',
                                label: '职位名称',
                                type:'text',
                                search:true
                            },{
                                prop: 'createTime',
                                label: '创建时间'
                            },{
                                prop: 'modifyTime',
                                label: '最后修改时间'
                            },{
                                prop: 'isValid',
                                label: '是否有效'
                            },{
                                prop: 'positionCode',
                                label: '职位代码',
                                type:'text',
                                search:true
                            }
                        ],
                        searchUrl:this.$api.API_MANAGEMENTHIERARCHY_LIST,
                        searchLabel:'职位信息',
                        proxy:'positionName',
                        searchProxy:'positionName',
                        queryProp:'fkPosition',
                        searchValue:'pkid'
                    },
                    {
                        prop:'r2RepCode',
                        label:'直属上司账号',
                        minWidth:'120'
                    },
                    {
                        prop:'r2RepName',
                        label:'直属上司姓名',
                        minWidth:'120'
                    },
                    {
                        prop:'aSMCode',
                        label:'ASM账号',
                        minWidth:'120'
                    },
                    {
                        prop:'aSMName',
                        label:'ASM姓名',
                        minWidth:'120'
                    },
                    {
                        prop:'rSMCode',
                        label:'RSM账号',
                        minWidth:'120'
                    },
                    {
                        prop:'rSMName',
                        label:'RSM姓名',
                        minWidth:'120'
                    },
                    {
                        prop:'sapCode',
                        label:'SAP代码',
                        minWidth:'120',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'isValid',
                        label:'状态',
                        minWidth: '60',
                        transfer: (val) => {
                          return val == 1 ? 'True' : 'False'
                        }
                    },
                    {
                        prop:'channel',
                        label:'用户所属渠道',
                        minWidth:'120'
                    },
                    {
                        prop:'hQOrRegion',
                        label:'总部/大区',
                        minWidth:'120',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'costCenter',
                        label:'成本中心',
                        minWidth:'80'
                    },
                    {
                        prop:'subDept',
                        label:'子部门',
                        minWidth:'80'
                    },
                    {
                        prop:'region',
                        label:'大区',
                        minWidth:'60'
                    },
                    {
                        prop:'area',
                        label:'Area',
                        minWidth:'60'
                    },
                    {
                        prop:'regionPMKT',
                        label:'大区-PMKT',
                        minWidth:'120'
                    },
                    {
                        prop:'areaPMKT',
                        label:'区域-PMKT',
                        minWidth:'120'
                    },
                    {
                        prop:'cityPMKT',
                        label:'城市-PMKT',
                        minWidth:'120'
                    }
                ],
                listUrl:this.$api.API_GETTPINFO_LIST,
                button:null,
                conditions:[],
                row:{},
                add:{
                    label:'人员信息',
                    addItems:[
                        {name:'员工编号',prop:'repCode',type:'text',readOnly:true},
                        {name:'真实姓名',prop:'repName',type:'text',readOnly:true},
                        {name:'所属管理层级',prop:'fkPosition',type:'select',optionsUrl:this.$api.API_MANAGEMENTHIERARCHY_LIST,optionProxy:'positionName',optionValue:'pkid'},
                        {name:'邮件地址',prop:'email',type:'text',readOnly:true},
                        {name:'手机号码',prop:'phone',type:'text',readOnly:true},
                        {name:'入职日期',prop:'inDate',type:'date'},
                        {name:'离职日期',prop:'outDate',type:'date'},
                        {name:'直属上司工号',prop:'r2RepCode',type:'text',readOnly:true},
                        {name:'WWID',prop:'wWID',type:'text',readOnly:true},
                        {name:'公司编码',prop:'companyCode',type:'text',readOnly:true},
                        {name:'公司部门',prop:'deptCode',type:'text',readOnly:true},
                        {name:'级别',prop:'level',type:'text',readOnly:true},
                        {name:'所属渠道',prop:'channel',type:'text',readOnly:true},
                        {name:'子部门',prop:'subDept',type:'text',readOnly:true},
                        {name:'大区',prop:'region',type:'text',readOnly:true},
                        {name:'区域',prop:'area',type:'text',readOnly:true},
                        {name:'大区-PMKT',prop:'regionPMKT',type:'text',readOnly:true},
                        {name:'区域-PMKT',prop:'areaPMKT',type:'text',readOnly:true},
                        {name:'城市-PMKT',prop:'cityPMKT',type:'text',readOnly:true},
                        {name:'SAP代码',prop:'sapCode',type:'text',readOnly:true},
                        {name:'总部/大区',prop:'hQOrRegion',type:'text',readOnly:true},
                        {name:'成本中心',prop:'costCenter',type:'text',readOnly:true},
                        {name:'备注',prop:'memo',type:'textarea',readOnly:true},
                    ],
                },
            }
        },
        methods:{
            onButtonClick(item) {
                if (item.event == 'edit()') {
                    if (!this.row || JSON.stringify(this.row) == '{}') {
                        this.$message.error("请选择一行数据")
                        return
                    }
                }
                if (item.event == 'add()') {
                    this.row = {}
                }

                this.button = item
            },
            editBack(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
            },
            conditionChange(conditions) {
                this.$refs.list.search()
            },
            close(item) {
                this.button = item
            }
        },
        components:{CommonExport, SearchPopUp, CommonList,CommonBtn,CommonEdit},
    }
</script>
